package com.supermali.entity.map.background.dynamic;

import com.supermali.behavior.jump.JumpBehavior;
import com.supermali.behavior.jump.land.BreakBrickJump;
import com.supermali.behavior.move.MoveBehavior;
import com.supermali.behavior.move.land.MonitorMove;
import com.supermali.creater.MapCreater;
import com.supermali.creater.img.ImgHelper;
import com.supermali.creater.img.ImgKey;
import com.supermali.creater.img.ImgLoader;
import com.supermali.util.Constant;

import java.awt.image.BufferedImage;

public class BreakBrick extends DynamicBackGroundMapAbstract {

    JumpBehavior jumpBehavior;

    MoveBehavior moveBehavior;

    public BreakBrick(Double x, Double y, MapCreater mapCreater) {
        super(x, y, mapCreater);
        jumpBehavior = new BreakBrickJump(this);
        moveBehavior=new MonitorMove(this);
    }

    @Override
    public void proccessData(long delta) {
//        super.proccessData(delta);
        if(!jumpBehavior.isOver()){
            jumpBehavior.jump();
        }
        if(!moveBehavior.isOver()){
            moveBehavior.move(delta);
        }
        if(getX()< Constant.destroyLineX){
            getMapCreater().getRemoves().add(this);
        }else if(getY()< Constant.destroyLineY){
            getMapCreater().getRemoves().add(this);
        }
    }

    @Override
    public void init() {
        ImgHelper imgHelper = ImgLoader.getImgHelper(ImgKey.Background.BREAK_BRICK);
        BufferedImage select = imgHelper.select(0);
        this.setBufferedImage(select);
    }

    public JumpBehavior getJumpBehavior() {
        return jumpBehavior;
    }

    public MoveBehavior getMoveBehavior() {
        return moveBehavior;
    }
}
